package nyu.edu.database;

import java.util.ArrayList;
import java.util.Scanner;

import nyu.edu.database.data.DataItem;
import nyu.edu.database.data.Site;
import nyu.edu.database.operation.Operation;
import nyu.edu.database.transaction.Transaction;

public class TransactionManager {
	private Site[] siteHandles = new Site[10];
	private static TransactionManager myManager;
	private ArrayList<Transaction> transactions;

	private TransactionManager() {
		for (int x = 0; x < siteHandles.length; x++) {
			siteHandles[x] = new Site(x + 1);
		}
		transactions = new ArrayList<Transaction>();
		DataItem[] myItems = DataItem.initializeDataItems();
		for (DataItem x : myItems) {
			if (x.getDataId() % 2 == 0) {
				for (Site z : siteHandles) {
					z.addDataItem(x);
				}
			} else {
				siteHandles[x.getDataId() % 10].addDataItem(x);
			}
		}
	}

	public static TransactionManager getInstance() {
		if (myManager == null) {
			myManager = new TransactionManager();
		}
		return myManager;
	}

	public static void main(String[] args) {
		Scanner myScanner = new Scanner(System.in);
		System.out.println("> ");
		myScanner.useDelimiter("\n");
		TransactionManager myManager = TransactionManager.getInstance();
		while (myScanner.hasNext()) {

			Operation[] myOperations = Operation
					.getOperationsFromInputString(myScanner.next());

			for (int x = 0; x < myOperations.length; x++) {
				System.out.println("Operation " + x + " has the properties "
						+ myOperations[x].toString());
			}

			System.out.print("> ");
		}

	}
}
